package com.my.test.design.strategy.Commission;

public enum CommissionEnum {

    A("a",new CommissionA()),

    B("b",new CommissionB()),

    C("c",new CommissionC());

    private CommissionStrategy strategy;

    private String name;

    // 构造方法里传入策略对象实例
    CommissionEnum(String name,CommissionStrategy strategy) {
        this.strategy = strategy;
        this.name = name;
    }

    public CommissionStrategy getStrategy() {
        return strategy;
    }

    public void setStrategy(CommissionStrategy strategy) {
        this.strategy = strategy;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 根据名称获取策略
     * @param name
     * @return
     */
    public static CommissionStrategy getStrategy(String name) {
        for(CommissionEnum commission :CommissionEnum.values()) {
            if (commission.name.equals(name)){
                return commission.strategy;
            }
        }
        return null;
    }
}
